//
//  SightseeingWebView.m
//  Lovelife
//
//  Created by dllo on 15/4/30.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SightseeingWebView.h"

@interface SightseeingWebView ()<UIWebViewDelegate>
@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicatorView;
@end

@implementation SightseeingWebView
- (void)dealloc
{
    [_url release];
    [_titleName release];
    [_webView release];
    [_activityIndicatorView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = self.titleName;
    
    self.view.backgroundColor = [UIColor whiteColor];
    //1.创建网络请求
    NSURL *url =[NSURL URLWithString:self.url];
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    self.webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.webView.backgroundColor = [UIColor grayColor];
    //2.设置WebView的代理
    self.webView.delegate = self;
    //伸缩内容适应屏幕尺寸
    self.webView.scalesPageToFit = YES;
    //加载网络请求
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
    [_webView release];
    
    
    // 旋转进度轮
    self.activityIndicatorView = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0.0, 0.0, 100, 100)] ;
    [self.activityIndicatorView setCenter:self.view.center];
    [self.activityIndicatorView setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray];
    [self.view addSubview:self.activityIndicatorView];
    [_activityIndicatorView release];
}


// WebView开始加载资源的时候调用（开始发送请求）
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [self.activityIndicatorView startAnimating] ;
}
// WebView加载完毕的时候调用（请求完毕）
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *meta = [NSString stringWithFormat:@"var ab = document.getElementById(\"bookmark\"); ab.firstChild.nodeValue = \"做法\";"];
    [webView stringByEvaluatingJavaScriptFromString:meta];
    [self.activityIndicatorView stopAnimating];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
